<?php
namespace app\admin\controller;
use app\BaseController;
use think\facade\Request;
use think\facade\Db;
use think\facade\View;
class Brand
{
    public function brandList()
    {
        //测试代码合并
        $keywords= Request::post('keywords');
        $post = Request::post();
        $whereOr= $where = [];
        if (isset($keywords) && $keywords <> '')                    $where[] = ['brand_name','like',"%{$keywords}%"];
        if (isset($post['recommended']) && $post['recommended'] <> "")      $where[] = ['recommended','=',$post['recommended']];
        if (isset($post['if_show']) && count($post['if_show'])==1)  $where[] = ['if_show','in',$post['if_show']];
        if (isset($post['brand_logo']) && count($post['brand_logo'])==1) {
            if ($post['brand_logo'][0] == 1) {
                $where[] = ['brand_logo', '<>', ''];
            } else {
                $whereOr[] = ['brand_logo','=',null];
                $whereOr[] = ['brand_logo','=',''];
            }
        }

        View::assign('keywords',$keywords);
        View::assign($post);
            $list = Db::table('ecm_brand')
                ->where($where)
                ->where(function ($q) use ($whereOr){$q->whereOr($whereOr);})
                ->order('sort_order asc')
                ->select();
            View::assign('list', $list);
        return View::fetch();
    }
}